package com.yowasa.xiuxian.engine.message.cmd;

import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.annoations.CMD;
import com.yowasa.xiuxian.annoations.SE;
import com.yowasa.xiuxian.engine.CommonEngine;
import com.yowasa.xiuxian.engine.battle.strategy.BattleStrategy;
import com.yowasa.xiuxian.engine.hone.SpecialInterface;
import com.yowasa.xiuxian.engine.message.CmdMessageHandler;
import com.yowasa.xiuxian.entity.enums.CmdScopeEnum;
import com.yowasa.xiuxian.entity.enums.ItemTypeEnum;
import com.yowasa.xiuxian.entity.enums.MapEnum;
import com.yowasa.xiuxian.entity.mys.SendMessage;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.MessageHelper;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 获取描述
 */
@CMD(name = "/图鉴", scope = CmdScopeEnum.ALL,outCmd = true)
public class HandBookHandler extends CmdMessageHandler {
    @Autowired
    private MessageHelper messageHelper;
    @Autowired
    private List<BattleStrategy> battleStrategies;
    @Override
    public void execute(SendMessage message) {
        String param = getParam(message);
        if (StringUtils.isEmpty(param)) {
            throw new HandlerException("请在指令后追加类型 : 丹药，灵药，装备，秘籍，素材，图纸，战技，神通");
        }

        if("丹药".equals(param) || "食物".equals(param)){
            Set<String> strings = CommonEngine.ITEM_MAP.keySet();
            List<String> collect = strings.stream().filter(e -> CommonEngine.ITEM_MAP.get(e).getType().getId() == 1).collect(Collectors.toList());
            messageHelper.replyMys(message, String.join("\n", collect));
        }
        if("灵药".equals(param) ){
            Set<String> strings = CommonEngine.ITEM_MAP.keySet();
            List<String> collect = strings.stream().filter(e -> CommonEngine.ITEM_MAP.get(e).getType().getId() == 2).collect(Collectors.toList());
            messageHelper.replyMys(message, String.join("\n", collect));
        }
        if("装备".equals(param)){
            Set<String> strings = CommonEngine.ITEM_MAP.keySet();
            List<String> collect = strings.stream().filter(e -> CommonEngine.ITEM_MAP.get(e).getType().getId() == 3).collect(Collectors.toList());
            messageHelper.replyMys(message, String.join("\n", collect));
        }
        if("秘籍".equals(param)){
            Set<String> strings = CommonEngine.ITEM_MAP.keySet();
            List<String> collect = strings.stream().filter(e -> CommonEngine.ITEM_MAP.get(e).getType().getId() == 4).collect(Collectors.toList());
            messageHelper.replyMys(message, String.join("\n", collect));
        }
        if("素材".equals(param)){
            Set<String> strings = CommonEngine.ITEM_MAP.keySet();
            List<String> collect = strings.stream().filter(e -> CommonEngine.ITEM_MAP.get(e).getType().getId() == 5).collect(Collectors.toList());
            messageHelper.replyMys(message, String.join("\n", collect));
        }
        if("图纸".equals(param)){
            Set<String> strings = CommonEngine.ITEM_MAP.keySet();
            List<String> collect = strings.stream().filter(e -> CommonEngine.ITEM_MAP.get(e).getType().getId() == 6).collect(Collectors.toList());
            messageHelper.replyMys(message, String.join("\n", collect));
        }

        if("战技".equals(param)){
            List<String> list = new ArrayList<String>();
            for (BattleStrategy e : battleStrategies) {
                BS annotation = e.getClass().getAnnotation(BS.class);
                if (annotation != null) {
                    list.add(annotation.name());
                }
            }
            messageHelper.replyMys(message, String.join("\n", list));
        }
        if("神通".equals(param)){
            Set<String> strings = CommonEngine.SPECIAL_EFFECT.keySet();
            messageHelper.replyMys(message, String.join("\n", strings));
        }

    }

    public String desc(){
        return new StringBuffer().append("全村最好用的指令！！！\n")
                .append("可以用来查看所有物品的效果，包括道具 地图 心法 战技 怪物等等\n")
                .append("当你不知道某件东西有什么用的时候，试着查看一下吧\n")
                .toString();

    }
}
